#include "File.h"

File::File(string filename) {
    this->filename = filename;
}

string File::readAllFile() {
    ifstream inputfile;
    string inputfilename = this->filename;    
    int length;
    char * buffer;
    inputfile.open(inputfilename.c_str(), ios::binary);

    // get length of file:
    inputfile.seekg(0, ios::end);
    length = inputfile.tellg();
    inputfile.seekg(0, ios::beg);

    // allocate memory:
    buffer = new char [length];

    // read data as a block:
    inputfile.read(buffer, length);

    inputfile.close();

    //cout.write(buffer, length);

    return buffer;
}

void File::writeToFile(const string& input){
    ofstream myfile;
    myfile.open(this->filename.c_str());    
    myfile<<input;
    myfile.close();
}

void File::writeAppendToFile(const string& input){
    ofstream myfile;
    myfile.open(this->filename.c_str(),ios::app);
    myfile<<input;
    myfile.close();
}
